package com.woniu.cq.malluser.client;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @author Daniel
 * @version 1.0.0
 * @ClassName TokenClient
 * @Description token feign支持
 * @createTime 2020年09月24日 17:49:00
 */
@Component
public class TokenClient implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes requestAttributes =(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = requestAttributes.getRequest().getHeader("X-Token");
        if (StringUtils.isNotEmpty(token)){
            requestTemplate.header("X-Token",token);
        }
    }
}
